%%  
% f(x)=|x+\xi|
clear  all;clc;
fobj=@(x)(abs(x+randn(1,1)));
gobj=@(x)(sign(x+randn(1,1)));
theta=0;
init=2;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=abs(path(:,i)-0);
end
loglog(v,'-')
grid on;
hold on;

theta=0.3;
init=2;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=abs(path(:,i)-0);
end
loglog(v,':')

theta=0.6;
init=2;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
for i=1:iter
    v(i)=abs(path(:,i)-0);
end
loglog(v,'--')



theta=0.9;
init=2;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);

for i=1:iter
    v(i)=abs(path(:,i)-0);
end
loglog(v,'-.')

% loglog(1:iter,norm(init)^2*(1:iter).^(-1/2),'ro');

% legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9','rate');

legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9');



%%  
% f(x)=(Ax-b)^2
clear  all;clc;
init=[0.13;0.6;0.5];
num=10;dim=length(init);
rand('seed',10);
U=randn(dim,dim);
A=randn(num,dim)*(U*U');
sol=rand(dim,1);
b=A*sol;
xi=unidrnd(num,1);
gobj=@(x)(gobj_lst(x,A,b));
theta=0;

[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-')
grid on;
hold on;

theta=0.7;

[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,':')

theta=0.8;

[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'--')



theta=0.9;

[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')



% loglog(1:iter,norm(init)^2*(1:iter).^(-1/2),'ro');

legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9');




%%  
% f(x)=norm(x+xi,1)
clear  all;clc;
init=zeros(100,1);
num=10000; dim=length(init);
rand('seed',10); z=rand(dim,1);
A=randn(num,dim)*(eye(dim)+z*z');
sol=rand(dim,1);
b=A*sol;
gobj=@(x)(gobj_abs(x,A,b));
theta=0;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-')
grid on;
hold on;
theta=0.3;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,':')
theta=0.6;

[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'--')
theta=0.9;
[x,path]=ssg_nag(gobj,init,theta);
[dim,iter]=size(path);
disp(x)
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')

legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9');
